package com.atguigu.java.ai.langchain4j.config;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.pinecone.PineconeEmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeServerlessIndexConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: Mikey
 * @Date: 2025/9/4 19:33
 * @Description:
 **/
@Configuration
public class EmbeddingStoreConfig {

    @Autowired
    private EmbeddingModel embeddingModel;

    @Bean
    public EmbeddingStore<TextSegment> embeddingStore(){
        //创建向量存储
        EmbeddingStore<TextSegment> embeddingStore = PineconeEmbeddingStore.builder()
                .apiKey("pcsk_6ZNDyp_4ySn5N4JaZvHykoJQyR5QJUMZijLBJ44822mDGt124gKbJNuz8nAh3oV4oSboL9")//密钥
                .index("2301a")//指定索引 若不存在就创建
                .nameSpace("xiaozhi-nameSpace") //指定命名空间 不存在就创建
                .createIndex(PineconeServerlessIndexConfig.builder()
                        .cloud("AWS") //指定索引部署在AWS云服务上
                        .region("us-east-1") //指定索引所在的AWS区域为 us-east-1
                        .dimension(embeddingModel.dimension())//指定索引的向量维度 和embeddingStore生成的向量维度相同
                        .build())
                .build();

        return embeddingStore;
    }
}